class Dep {
  constructor() {
    this.subscribers = new Set()  //集合 内容不会重复
  }

  addEffect(effect) {
    this.subscribers.add(effect)  //集合的方法 add（添加）
  }

  notify() {
    this.subscribers.forEach(effect => {
      effect()
    })
  }
}

const dep = new Dep()

const info = {
  counter: 10
}
function doubleCounter() {
  console.log(info.counter * 2);
}
function powerCounter() {
  console.log(info.counter * info.counter);
}

dep.addEffect(doubleCounter)
dep.addEffect(powerCounter)

// info.counter++;
dep.notify()


